package com.ruoyi.system.config;

import com.alibaba.druid.pool.DruidDataSource;
import io.seata.rm.datasource.DataSourceProxy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Configuration
@Slf4j
public class DBConfig {
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource.dynamic.druid")
    public DataSource druidDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        log.info("create druid dataSource ......");
        return dataSource;
    }

    @Bean
    @Primary
    public DataSource dataSource() {
        log.info("create seata dataSourceProxy");
        return new DataSourceProxy(druidDataSource());
    }
}
